package com.hqd.jjvm.classformat.attributeinfo;

import com.hqd.jjvm.classformat.ClassFile;
import com.hqd.jjvm.util.HexStrTransformUtil;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class EnclosingMethod extends AttributeInfo {
	private Integer classIndex;
	private Integer methodIndex;

	public EnclosingMethod(Integer attributeNameIndex, Integer attributeLength, Integer classIndex, Integer methodIndex) {
		super(attributeNameIndex, attributeLength);
		this.classIndex = classIndex;
		this.methodIndex = methodIndex;
	}

	@Override
	protected EnclosingMethod newAttributeInfo(Integer attributeNameIndex, Integer attributeLength, ClassFile classFile) {
		this.classIndex = HexStrTransformUtil.parseHexToInt(classFile.readU2());
		this.methodIndex = HexStrTransformUtil.parseHexToInt(classFile.readU2());
		return this;
	}
}
